$(function () {
  //  getbrach();
    getBrachValuebyDay();
    options.color[0]='#3398DB';
    getBrachValuebyM();
    options.color[0]='#3398DB';
    getCountBaby();
    getPayAndTurnover();
    options.color[0]='#3398DB';
    getVipCardCount();
    options.color[0]='#3398DB';
    getYearPay();
    options.color[0]='#3398DB';
});


options = {
    title: {
        text: '总店统计数据'
    },
    color: ['#3398DB'],
    tooltip: {
        trigger: 'axis',
        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    grid: {
        left: '1%',
        right: '2%',
        bottom: '4%',
        containLabel: true
    },
    xAxis: [
        {
            type: 'category',
            data: null,
            axisTick: {
                alignWithLabel: true
            }
        }
    ],
    yAxis: [
        {
            type: 'value',
            name: '金额',
            axisLabel: {
                formatter: '{value}'
            }
        }
    ],
    series: [
        {
            name: '营业额',
            type: 'bar',
            barWidth: '60%',
            data: null
        }
    ]
};

options1 = {
    title: {
        text: '总店统计数据'
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'cross',
            crossStyle: {
                color: '#999'
            }
        }
    },
    toolbox: {
        feature: {
            dataView: {show: true, readOnly: false},
            magicType: {show: true, type: ['line', 'bar']},
            restore: {show: true},
            saveAsImage: {show: true}
        }
    },
    legend: {
        data: ['会员消费金额汇总', '会员充值金额汇总']
    },
    xAxis: [
        {
            type: 'category',
            data: [],
            axisPointer: {
                type: 'shadow'
            }
        }
    ],
    yAxis: [
        {
            type: 'value',
            name: '金额',
            interval: 1000,
            axisLabel: {
                formatter: '{value} 元'
            }
        }
    ],
    series: [
        {
            name: '会员消费金额汇总',
            type: 'bar',
            data: []
        },
        {
            name: '会员充值金额汇总',
            type: 'bar',
            data: []
        }
    ]
};


function getReqyest(url) {
    var result;
    $.ajax({
        url: url,
        type: 'get',
        cache: false,
        async: false,
        //    data: formData,
        processData: false,
        contentType: false
    }).done(function (res) {
        console.log(res);
        if (res.success !== null || res.success !== undefined || res.success !== '') {
            result = res;
        }
    }).fail(function (res) {
        console.log(res);
    });
    return result;
}

/**
 * 按照一年中的月份统计数据
 */

function getYearPay() {
    var xData = new Array();
    var yData = new Array();
    var url = "/count/getYearPay";
    var res = getReqyest(url);
    if (res != null && res != undefined && res != '') {
        if (res.success !== undefined && res.success) {
            $.each(res.data, function () {
                console.log(this);
                xData.push(this.month+'月');
                yData.push(this.pay);
            })
        }
    }
    var dom = document.getElementById("container6");
    var myChart = echarts.init(dom);
    options.title.text = "本年度营业统计";
    options.color[0]='#dc152d';
    $.each(options.series, function () {
        this.name = "营业额";
    });
    $.each(options.yAxis, function () {
        this.name = "金额";
    });
    $.each(options.xAxis, function () {
        this.data = xData;
    });
    $.each(options.series, function () {
        this.data = yData;
    });
    if (options && typeof options === "object") {
        myChart.setOption(options, true);
    }
}


/**
 * 各个会员卡下的用户数量
 */
function getVipCardCount() {
    var xData = new Array();
    var yData = new Array();
    var url = "/count/getVipCardCount";
    var res = getReqyest(url);
    if (res != null && res != undefined && res != '') {
        if (res.success !== undefined && res.success) {
            $.each(res.data, function () {
                console.log(this);
                xData.push(this.vipName);
                yData.push(this.count)
            })
        }
    }
    var dom = document.getElementById("container5");
    var myChart = echarts.init(dom);
    options.title.text = "各等级会员卡下的用户数量统计";
    $.each(options.xAxis, function () {
        this.data = xData;
    });
    $.each(options.yAxis, function () {
        this.name = "名";
    });
    $.each(options.series, function () {
        this.data = yData;
        this.name = "人数";
    });
    if (options && typeof options === "object") {
        myChart.setOption(options, true);
    }
}


/**
 *统计个分店的充值金额个营业金额
 */

function getPayAndTurnover() {
    var url = "/count/getTurnoverAndPay";
    var nameData = new Array();
    var payData = new Array();
    var turnoverData = new Array();
    var res = getReqyest(url);
    if (res != null && res != undefined && res != '') {
        if (res.success !== undefined && res.success) {
            $.each(res.data, function () {
                console.log(this);
                nameData.push(this.branName);
                turnoverData.push(this.turnover);
                payData.push(this.pay);
            })
        }
    }

    var dom = document.getElementById("container4");
    var myChart = echarts.init(dom);
    options1.title.text = "各分店历史营业情况";
    $.each(options1.xAxis, function () {
        this.data = nameData;
    });
    options1.series[1].data=payData;
    options1.series[0].data=turnoverData;
   /* $.each(options1.series, function () {
        this.data = payData;
    });*/
    if (options1 && typeof options1 === "object") {
        myChart.setOption(options1, true);
    }
}

/**
 * 根据分店统计宝宝数量
 */
function getCountBaby() {
    var xData = new Array();
    var yData = new Array();
    var url = "/count/getCountBaby";
    var res = getReqyest(url);
    if (res != null && res != undefined && res != '') {
        if (res.success !== undefined && res.success) {
            $.each(res.data, function () {
                console.log(this);
                xData.push(this.branName);
                yData.push(this.turnover)
            })
        }
    }
    var dom = document.getElementById("container3");
    var myChart = echarts.init(dom);
    options.title.text = "分店宝宝数统计";
    options.color[0]='#9cc5b2';
    $.each(options.xAxis, function () {
        this.data = xData;
    });
    $.each(options.yAxis, function () {
        this.name = "名";
    });
    $.each(options.series, function () {
        this.data = yData;
        this.name = "人数";
    });
    if (options && typeof options === "object") {
        myChart.setOption(options, true);
    }
}


/**
 * 分店日统计表
 */
function getBrachValuebyDay() {
    var xData = new Array();
    var yData = new Array();
    var url = "/count/getbrachvaluebyD";
    var res = getReqyest(url);
    if (res != null && res != undefined && res != '') {
        if (res.success !== undefined && res.success) {
            $.each(res.data, function () {
                console.log(this);
                xData.push(this.branName);
                yData.push(this.turnover)
            })
        }
    }
    var dom = document.getElementById("container1");
    var myChart = echarts.init(dom);
    options.title.text = "分店本日营业额数据统计表";
    options.color[0]='#D4b265';
    $.each(options.xAxis, function () {
        this.data = xData;
    });
    $.each(options.series, function () {
        this.data = yData;
    });
    if (options && typeof options === "object") {
        myChart.setOption(options, true);
    }
}

/**
 * 分店月统计表
 */
function getBrachValuebyM() {
    var xData = new Array();
    var yData = new Array();
    var url = "/count/getbrachvaluebyM";
    var res = getReqyest(url);
    if (res != null && res != undefined && res != '') {
        if (res.success !== undefined && res.success) {
            $.each(res.data, function () {
                console.log(this);
                xData.push(this.branName);
                yData.push(this.turnover)
            })
        }
    }
    var dom = document.getElementById("container2");
    var myChart = echarts.init(dom);
    options.title.text = "各分店本月营业额数据统计表";
    $.each(options.xAxis, function () {
        this.data = xData;
    });
    $.each(options.series, function () {
        this.data = yData;
    });
    if (options && typeof options === "object") {
        myChart.setOption(options, true);
    }
}


function getbrach() {
    var xData = new Array();
    var yData = new Array();
    var url = "/count/getbrach";
    var res = getReqyest(url);
    console.log("-----------");
    console.log(res);
    if (res != null && res != undefined && res != '') {
        if (res.success !== undefined) {
            $.each(res.data, function (item) {
                console.log(this);
                xData.push(this.branName + item);
                yData.push(this.reserve4)
            })
        }
    }
    var dom1 = document.getElementById("container4");
    var myChart = echarts.init(dom1);

    var app = {};
    //  option = null;
    app.title = '坐标轴刻度与标签对齐';
    $.each(options.xAxis, function () {
        this.data = xData;
    });
    $.each(options.series, function () {
        this.data = yData;
    });
    if (options && typeof options === "object") {
        myChart.setOption(options, true);
    }

}